from sqlalchemy import Column, Integer, String, Text, Float, JSON, DateTime, ForeignKey
from sqlalchemy.sql import func
from ..database import Base

class Question(Base):
    __tablename__ = "questions"

    id = Column(Integer, primary_key=True, index=True)
    subject = Column(String(10), nullable=False, index=True)  # k1, k4
    vehicle_type = Column(String(10), nullable=False, index=True)  # A1, B1, C1等
    question_type = Column(String(20), nullable=False, index=True)  # 单选、多选等
    exam_type = Column(String(20), nullable=False, index=True)  # theory, special, sequence
    content = Column(Text, nullable=False)
    options = Column(JSON)  # 选项
    correct_answer = Column(String(50), nullable=False)
    explanation = Column(Text)  # 解释
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), onupdate=func.now())

class QuestionRecord(Base):
    __tablename__ = "question_records"

    id = Column(Integer, primary_key=True, index=True)
    user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
    subject = Column(String(10), nullable=False)
    score = Column(Float, nullable=False)
    answers = Column(JSON)  # 用户答案记录
    created_at = Column(DateTime(timezone=True), server_default=func.now()) 